// 在 utils 文件夹下新建 message.js 文件

export function successMessage(message) {
	showMessage(message,'success')
}

export function errorMessage(message) {
	showMessage(message,'error')
}

export function warningMessage(message) {
	showMessage(message,'warning')
}

function showMessage(message, type, duration = 2000) {
	let iconClass = '';
	switch (type) {
		case 'success':
			iconClass = 'success';
			break;
		case 'error':
			iconClass = 'error';
			break;
		case 'warning':
			iconClass = 'warning';
			break;
		default:
			iconClass = 'warning';
	}
	// 添加自定义样式
	setTimeout(() => {
		uni.showToast({
			title: message,
			icon: 'none',
			image: `/static/icon/${iconClass}.png`, // 根据不同类型显示不同图标
			duration: duration
		});
	}, 100);
}